//
// Created by Administrator on 2021/5/19.
//
#include <vector>
#include <iostream>
#include <climits>
using namespace std;

class Solution {
public:
    int nthSuperUglyNumber(int n, vector<int> &primes) {
        vector<int> container;
        container.push_back(1);
        auto size = primes.size();
        vector<int> primeIndex(size, 0); // 质数序列
        vector<int> primeAns(size, 0);   // 质数结果
        for (int i = 0; i < n-1; ++i) {
            int temp = INT_MAX;
            for (int j = 0; j < size; ++j) {
                primeAns[j] = primes[j] * container[primeIndex[j]];
                temp = min(primeAns[j],temp);
            }
//            cout << temp << endl;
            container.push_back(temp);
            for(int j = 0;j<size;++j){
                if (temp == primeAns[j]) ++ primeIndex[j];
            }
        }
        return container.back();
    }
};

int main() {
    vector<int> prime{2, 7, 13, 19};
    Solution sol;
    cout << sol.nthSuperUglyNumber(12, prime) << endl;
    return 0;
}